package com.zm.demo.core.concurrent;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author zoum
 * @create 2019/12/16 13:32
 */
public class ScheduledThreadPoolTest {

    public static void main(String[] args) throws Exception{
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
        executorService.scheduleAtFixedRate(() ->{
            System.out.println("scheduleAtFixedRate..." + System.currentTimeMillis());
        },2, 3, TimeUnit.SECONDS);
        executorService.scheduleWithFixedDelay(() ->{
            System.out.println("scheduleWithFixedDelay" + System.currentTimeMillis());
        },2, 3, TimeUnit.SECONDS);

        Thread.sleep(10000L);
        executorService.shutdown();
    }
}
